package com.guli.gulimall.gulimallproduct.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.AlternateTypeRules;
import springfox.documentation.schema.Model;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

@Configuration
@EnableSwagger2
public class SwagerConfig {
    String title = "谷粒商城";
    String description = "谷粒商城api";
    String version = "1.1.1";

    //    String termsOfServiceUrl
//    Contact contact,
//    String license,
//    String licenseUrl,
//    Collection<VendorExtension> vendorExtensions)
    @Bean
    public Docket docket() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .enable(true)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.guli.gulimall.gulimallproduct"))
                .paths(PathSelectors.any())
                .build();
        docket.alternateTypeRules(AlternateTypeRules.newMapRule(String.class, List.class));
        docket.alternateTypeRules(AlternateTypeRules.newMapRule(List.class, Model.class));
        docket.alternateTypeRules(AlternateTypeRules.newMapRule(String.class, String.class));
        docket.alternateTypeRules(AlternateTypeRules.newMapRule(String.class, Object.class));
        return docket;
    }

    public ApiInfo apiInfo() {
        return new ApiInfoBuilder().title(title)
                .description(description) // 设置文档的描述
                .version(version) // 设置文档的版本信息-> 1.0.0 Version information
//                .termsOfServiceUrl("www.") // 设置文档的License信息->1.3 License information
                .contact(new Contact("zouzhi", "localhost:8018/doc.html", "1245268075@qq.com"))
                .build();
    }



}
